package com.demo.core.controller;

import com.demo.base.page.IPagableDTO;
import com.demo.base.page.PagableDTO;
import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.demo.base.model.FullTimeJob;
import com.demo.base.util.CommonUtil;
import com.demo.core.service.FullTimeJobService;

/**
 * 全职信息
 * Created by xiajun on 2017/4/5.
 */
@RequestMapping("/FullTime")
@Controller
public class FullTimeJobController {
	
    @Autowired
    private FullTimeJobService fullTimeJobService;

    /**
     * 添加或更改全职信息
     */
    @ResponseBody
    @RequestMapping("/newOrupdateFullTimeJob")
    public Map<String,Object> newOrupdateFullTimeJob(@RequestBody FullTimeJob fullTimeJob){
        
    	Map<String,Object> map = new HashMap<String,Object>();
    	try {
            fullTimeJobService.newOrupdateFullTimeJob(fullTimeJob);
        }catch (Exception e){
        	map.put("status", CommonUtil.FAIL);
        	map.put("message", "操作失败");
            return map;
        }
    	
    	map.put("status", CommonUtil.SUCCESS);
    	map.put("message", "操作成功");
        return map;
    }

    /**
     * 根据id查询全职信息
     */
    @ResponseBody
    @RequestMapping("/getFullTimeJobById")

    public Map<String,Object> getFullTimeJobById(@RequestBody FullTimeJob fullTimeJob){
    	
    	Map<String,Object> map = new HashMap<String,Object>();
        try {
        	fullTimeJob = fullTimeJobService.getFullTimeJobById(fullTimeJob.getId());
        }catch (Exception e){
        	map.put("status", CommonUtil.FAIL);
        	map.put("message", "查询失败");
            return map;
        }
        map.put("status", CommonUtil.SUCCESS);
        map.put("message", "查询成功");
        map.put("data", fullTimeJob);
        return map;
    }

    //根据多个条件获取全职信息
    @ResponseBody
    @RequestMapping("/getFullTimeJobByQuery")

    public Map<String,Object> getFullTimeJobByQuery(@RequestBody FullTimeJob fullTimeJob, int startRow, int pageSize){
        
    	Map<String,Object> map = new HashMap<String,Object>();
    	IPagableDTO<FullTimeJob> iPagableDTO = null;
    	try {
            IPagableDTO<FullTimeJob> pagableDTO = new PagableDTO<FullTimeJob>();
            pagableDTO.setStartRow(startRow);
            pagableDTO.setPageSize(pageSize);
            iPagableDTO = fullTimeJobService.getFullTimeJobByQuery(fullTimeJob, pagableDTO);
        }catch (Exception e){
        	map.put("status", CommonUtil.FAIL);
        	map.put("message", "获取数据失败");
            return map;
        }
    	
    	map.put("status", CommonUtil.SUCCESS);
    	map.put("message", "获取数据成功");
    	map.put("data", iPagableDTO);
        return map;
    }

    //删除单条或多条全职信息
    @ResponseBody
    @RequestMapping("/delteFullTimeJobById")
    public Map<String,Object> delteFullTimeJobById(@RequestBody String ids){
    	Map<String,Object> map = new HashMap<String,Object>();
        try{
            fullTimeJobService.delteFullTimeJobById(ids);
        }catch(Exception e){
        	map.put("status", CommonUtil.FAIL);
        	map.put("message", "删除失败");
            return map;
        }
        map.put("status",CommonUtil.SUCCESS);
        map.put("message", "删除成功");
        return map;
    }

    /**
     * //关注数，每次新增1
     * @param noticeId
     * @return
     */
    @ResponseBody
    @RequestMapping("/addFollowNumber")
    public Map<String,Object> addFollowersNumber(@RequestBody String noticeId){

    	Map<String,Object> map = new HashMap<String,Object>();
        try {
            fullTimeJobService.addFollowersNumber(noticeId);
        } catch (Exception e) {
        	
        	map.put("status", CommonUtil.FAIL);
        	map.put("message", "关注失败");
            return map;
        }
        
        map.put("statu", CommonUtil.SUCCESS);
        map.put("message", "关注成功");
        return map;
    }

    /**
     * //男生报名数，每次新增1
     * @param id
     * @return
     */
    @ResponseBody
    @RequestMapping("/addManNumber")
    public String addManEnterNumber(@RequestBody String id){

        try {
            fullTimeJobService.addManEnterNumber(id);
        } catch (Exception e) {
            return CommonUtil.FAIL;
        }
        return CommonUtil.SUCCESS;
    }

    /**
     * //女生报名数，每次新增1
     * @param id
     * @return
     */
    @ResponseBody
    @RequestMapping("/addWoManNumber")
    public String addWoManEnterNumber(@RequestBody String id){

        try {
            fullTimeJobService.addWoManEnterNumber(id);
        } catch (Exception e) {
            return CommonUtil.FAIL;
        }
        return CommonUtil.SUCCESS;
    }
}
